package com.example.contrl;

import com.example.pojo.ParseStudent;
import com.example.pojo.ParseTeacher;
import com.example.pojo.Result;
import com.example.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Vector;

@Slf4j
@RestController
public class TeacherContrl {
    @Autowired
    TeacherService teacherService;

    /*
     * 查询老师
     * */
    @PostMapping("/teacher")
    public Result teacher(){
        log.info("查询学生");
        Vector<ParseTeacher> students=teacherService.select();
        return Result.success(students);
    }

    /*
     * 查询全部老师
     * */
    @PostMapping("/teachers")
    public Result teachers(){
        log.info("查询全部老师");
        ArrayList<String> teacherss=teacherService.selectTeachers();
        return Result.success(teacherss);
    }

    /*
     * 条件查询老师
     * */
    @GetMapping("/selectTeacher")
    public Result  selectTeacher( String name, String department,String id){
        log.info("查询老师{}，{}",name,department,id);
        Vector<ParseTeacher> teachers=teacherService.selectTeacher(name,department,id);
        return Result.success(teachers);
    }

    /*
     * 修改老师
     * */
    @PostMapping("/teacher/update")
    public Result updateStudent(@RequestBody ParseTeacher parseTeacher){
        log.info("修改{}",parseTeacher);
        teacherService.update(parseTeacher);
        return Result.success();
    }

    /*
     * 删除老师
     * */
    @GetMapping("/teacher/delete/{name}")
    public Result deleteStudent(@PathVariable String name){
        log.info("删除老师{}",name);
        teacherService.delete(name);
        return Result.success();
    }

    /*
    * 添加老师
    * */
    @PostMapping("/teacher/insert")
    public Result addTeacher(@RequestBody ParseTeacher teacher){
        log.info("添加老师：{}",teacher);
        teacherService.addTeacher(teacher);
        return Result.success();
    }


}
